import 'package:flutter/material.dart';
import 'package:flutter_app/getx/controller.dart';
import 'package:flutter_app/openeye/utils/toast_utils.dart';
import 'package:flutter_app/widget/app_float_box.dart';

///author: create by SunJH
///时间: 2022/1/14 0014
///邮箱: 965989158@qq.com
///描述: 可滑动按钮测试页面

class OverlayToolPage extends StatelessWidget {
   OverlayToolPage({Key? key}) : super(key: key);
  AppFloatBox appFloatBox = AppFloatBox(150,150,child: Container(
    width: 100,
    height: 100,
    decoration: const BoxDecoration(
        shape:  BoxShape.circle,
        color: Colors.red,
        boxShadow: [BoxShadow(color: Colors.blue,blurRadius:20)]
    ),
    child: TextButton(child: const Text("悬浮球"),onPressed: (){
      ToastUtils.showTip("点击了悬浮球");
    },),
  ),);

  @override
  Widget build(BuildContext context) {
    OverlayEntry entry = OverlayEntry(
        builder: (context) => appFloatBox);
    return Scaffold(
      body: Center(
        child: Container(
          alignment: Alignment.center,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              TextButton(
                child: const Text("添加圆球",style: TextStyle(fontSize: 24),),
                onPressed: (){
                  Overlay.of(context)?.insert(entry);
                },
              ),
              TextButton(
                child: const Text("显示圆球",style: TextStyle(fontSize: 24),),
                onPressed: (){
                  appFloatBox.refShowOrGoneFloatBox(true);
                },
              ),
              TextButton(
                child: const Text("隐藏悬浮球",style: TextStyle(fontSize: 24),),
                onPressed: () {
                  appFloatBox.refShowOrGoneFloatBox(false);
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}

// class OverlayToolPage extends StatefulWidget {
//    OverlayToolPage({Key? key}) : super(key: key);
//
//   @override
//   _OverlayToolPageState createState() => _OverlayToolPageState();
// }
//
// class _OverlayToolPageState extends State<OverlayToolPage> {
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       body: Center(
//         child: Container(
//           alignment: Alignment.center,
//           child: Column(
//             mainAxisAlignment: MainAxisAlignment.center,
//             children: <Widget>[
//               TextButton(
//                 child: const Text("显示圆球",style: TextStyle(fontSize: 24),),
//                 onPressed: (){
//                   widget.appFloatBox.refShowOrGoneFloatBox(true);
//                 },
//               ),
//               TextButton(
//                 child: const Text("隐藏悬浮球",style: TextStyle(fontSize: 24),),
//                 onPressed: () {
//                   widget.appFloatBox.refShowOrGoneFloatBox(false);
//                 },
//               ),
//             ],
//           ),
//         ),
//       ),
//     );
//   }
// }

